package com.example.demo.controller;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.AsyncRestTemplate;

import com.example.demo.model.Dto;
import com.example.demo.service.RestCallOrchestratorService;
import com.example.demo.service.Service;
import com.example.demo.service.Service2;

@RestController
public class RC {

	private static final AsyncRestTemplate restTemplate = new AsyncRestTemplate();

	@Bean
	public AsyncRestTemplate art() {
		return this.restTemplate;
	}

	@Autowired
	RestCallOrchestratorService restCallOrchestratorService;

	@Autowired
	Service service;

	@Autowired
	Service2 service2;

	@GetMapping("/")
	public String get() throws InterruptedException, ExecutionException {
		Dto dto = new Dto((int) (System.nanoTime() % 1000), "hi");
		Future<Dto> k = service.test(dto);
		service2.processThis(k, service);
		return "hi";
	}

	@GetMapping("/tp")
	public ResponseEntity<String> gettp() throws InterruptedException {
		Thread.sleep(2000);
		return new ResponseEntity<String>(HttpStatus.OK);
	}

	@GetMapping("/multi")
	public List<String> callmulti() throws Exception {
		return restCallOrchestratorService.getmulti();
	}

}
